#include "masterGetCycleHost.h"
#include "stdlib.h"
int main(){
	uint16_t itera;
	Event initGetCycle;
	Event innerRxEvent={HAND_SHAKE_MACHINE_RX_EVENT_CODE,NULL};
	Event innerTimeOut={HAND_SHAKE_MACHINE_TIMEOUT_EVENT_CODE,NULL};
	getInitData ponte;
	uint8_t bufferSpace[100];
	ponte.contentBuffer=&bufferSpace;
	initGetCycle.signature=INIT_CODE;
	for (itera=0;itera<100;itera++)
		bufferSpace[itera]=0;
	initGetCycle.data=&ponte;
	MasterMachine mean;
	stateMachineOnInit2(&mean,masterGetCycleHostInitTransactionState,&initGetCycle); //parti
	mean.microCycleHandler.sizeRx=2;//simula arrivo dati
	mean.microCycleHandler.RxBuffer[0]=10;
	mean.microCycleHandler.RxBuffer[1]=0;
	stateMachineDispatcher(&mean.microCycleHandler,&innerTimeOut);
	stateMachineDispatcher(&mean.microCycleHandler,&innerRxEvent);
	for (itera=0;itera<10;itera++)
	{
		mean.microCycleHandler.sizeRx=1;
		mean.microCycleHandler.RxBuffer[0]=(uint8_t)itera;
		stateMachineDispatcher(&mean.microCycleHandler,&innerRxEvent);
	}
	mean.microCycleHandler.sizeRx=0;
	stateMachineDispatcher(&mean.microCycleHandler,&innerRxEvent); //arrivo end
	//secondo test
	stateMachineOnInit2(&mean,masterGetCycleHostInitTransactionState,&initGetCycle); //parti
	mean.microCycleHandler.sizeRx=2;//simula arrivo dati
	mean.microCycleHandler.RxBuffer[0]=10;
	mean.microCycleHandler.RxBuffer[1]=0;
	stateMachineDispatcher(&mean.microCycleHandler,&innerTimeOut);
	stateMachineDispatcher(&mean.microCycleHandler,&innerRxEvent);
	for (itera=0;itera<10;itera++)
	{
		mean.microCycleHandler.sizeRx=1;
		mean.microCycleHandler.RxBuffer[0]=(uint8_t)itera;
		stateMachineDispatcher(&mean.microCycleHandler,&innerRxEvent);
	}
	for (itera=0;itera<10;itera++)
		stateMachineDispatcher(&mean.microCycleHandler,&innerTimeOut); //caso end perso
	//terzo test
	stateMachineOnInit2(&mean,masterGetCycleHostInitTransactionState,&initGetCycle); //parti
	mean.microCycleHandler.sizeRx=2;//simula arrivo dati
	mean.microCycleHandler.RxBuffer[0]=10;
	mean.microCycleHandler.RxBuffer[1]=0;
	stateMachineDispatcher(&mean.microCycleHandler,&innerTimeOut);
	stateMachineDispatcher(&mean.microCycleHandler,&innerRxEvent);
	for (itera=0;itera<10;itera++)
			stateMachineDispatcher(&mean.microCycleHandler,&innerTimeOut); //caso comunicazione persa
	while(1)
	{
		;
	}
}
